//
//  SelectPopoDelegate.m
//  CenturyCity
//
//  Created by beisheng03 on 2018/1/2.
//  Copyright © 2018年 beisheng. All rights reserved.
//

#import "SelectPopoDelegate.h"
#import "SelectPresentVC.h"
@implementation SelectPopoDelegate

#pragma mark- 转场代理
- (nullable UIPresentationController *)presentationControllerForPresentedViewController:(UIViewController *)presented presentingViewController:(UIViewController *)presenting sourceViewController:(UIViewController *)source{
    
    
    SelectPresentVC *temp = [[SelectPresentVC alloc]initWithPresentedViewController:presented presentingViewController:presenting];
    
    temp.model = self.model;
    
    return temp;
    
}

- (nullable id <UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source{
    return self;
}

- (nullable id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed{
    
    return  self;
    
}

- (NSTimeInterval)transitionDuration:(nullable id <UIViewControllerContextTransitioning>)transitionContext{
    
    return 0.25;
}

- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext{
    
    UIView *presentView = [transitionContext viewForKey:UITransitionContextToViewKey];
    
    if (presentView) {
        
        [[transitionContext containerView] addSubview:presentView];
        
        presentView.transform =  CGAffineTransformMakeScale(0.0001, 0.0001);
        
        //        presentView.transform = CGAffineTransformMakeTranslation([UIScreen mainScreen].bounds.size.width, 0);
        [transitionContext containerView].backgroundColor = [UIColor whiteColor];
        
        //执行动画
        [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
            presentView.transform = CGAffineTransformIdentity;
        } completion:^(BOOL finished) {
            [transitionContext completeTransition:YES];
            
        }];
        
        
        
        
    } else {
        //取出消失的View
        UIView *disView =  [transitionContext viewForKey:UITransitionContextFromViewKey];
        
        
        [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
            
            //            disView.transform = CGAffineTransformMakeTranslation([UIScreen mainScreen].bounds.size.width, 0);
            
            
            disView.transform =  CGAffineTransformMakeScale(0.0001, 0.0001);
            
        }completion:^(BOOL finished) {
            
            [transitionContext completeTransition:YES];
            
        }];
        
        
        
        
    }
    
}

@end
